#define F_CPU	16000000UL
#include <util/delay.h>

void delay_us(unsigned int time_us)
{
	register unsigned char i;

	for(i=0; i<time_us; i++)		// 4cycle+
	{
		asm volatile("PUSH R0");	// 2cycle+
		asm volatile("POP R0");		// 2cycle+ // 250ns
		asm volatile("PUSH R0");	// 2cycle+
		asm volatile("POP R0");		// 2cycle+
		asm volatile("PUSH R0");	// 2cycle+
		asm volatile("POP R0");		// 2cycle = 16cycle = 1us for 16MHz
	}
}

void delay_ms(unsigned int time_ms)
{
	register unsigned char i;
	
	for(i=0; i<time_ms; i++)
	{
		delay_us(250);
		delay_us(250);
		delay_us(250);
		delay_us(250);
	}
}


void delay_s(unsigned int time_ms)
{
	register unsigned char i;
	
	for(i=0; i<time_ms; i++)
	{
		delay_ms(250);
		delay_ms(250);
		delay_ms(250);
		delay_ms(250);
	}
}


void delay(unsigned char time)
{
	while(--time);
}
